import Vue from 'vue'
import VueRouter from 'vue-router'

/**
 * 修稿默认push 方法, 防止重复跳转
 **/
const original = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return original.call(this, location).catch(err => err);
};

const aboriginal = VueRouter.prototype.replace;

VueRouter.prototype.replace = function replace(location) {
  return aboriginal.call(this, location).catch(err => err);
};

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    component: () => import(/* webpackChunkName: "home" */ "views/home/Home")
  },
  {
    path: '/category',
    component: () => import(/* webpackChunkName: "category" */ "views/category/Category")
  },
  {
    path: '/profile',
    component: () => import(/* webpackChunkName: "profile" */ "views/home/Profile")
  },
  {
    path: '/shoppingCart',
    component: () => import(/* webpackChunkName: "shoppingCart" */ "views/cart/ShoppingCart")
  },
  {
    path: '/detail/:id',
    component: () => import(/* webpackChunkName: "detail" */ "views/detail/Detail")
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
